home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / VariablePrintln.java < prev    next >
Text File  |  1998-09-29  |  3KB  |  65 lines

  1. import java.lang.*;
  2. import com.symantec.itools.vcafe.macro.VisualCafeCommand;
  3. import com.symantec.itools.vcafe.openapi.*;
  4.  
  5. /*
  6.     Variable Println Macro
  7.  
  8.     VCafe macro that creates a System.out.println with the variable
  9.     that the cursor is currently on.  If the cursor is not on a word
  10.     it will make a println with empty quotes.
  11. */
  12.  
  13. public class VariablePrintln extends java.lang.Object
  14. {
  15.  
  16.     com.symantec.itools.vcafe.openapi.VisualCafe vcMainCafe;
  17.     com.symantec.itools.vcafe.openapi.SourceFile sfSource;
  18.  
  19.     public void run()
  20.     {
  21.         com.symantec.itools.vcafe.openapi.Range rSelectedWord, rCurrentPos;  //Positons of cursor
  22.         Object oFrontMostWin;                   //The source file working with
  23.         String sVarSelected;                    //The variable the cursor is on
  24.         StringBuffer sbRange;                   //The Range that has the selected var
  25.         StringBuffer sbThePrintln;              //VCafe Open API uses stringbuffer
  26.         String sVarLn;                          //The line to insert
  27.  
  28.  
  29.         sVarSelected = "";
  30.         // 1. Get the open source window
  31.         vcMainCafe = VisualCafe.getVisualCafe();
  32.         oFrontMostWin = vcMainCafe.getFrontmostWindow();
  33.         if(! (oFrontMostWin instanceof SourceFile)) return;  // A source window doesn't have focus
  34.         else sfSource = (SourceFile)oFrontMostWin;
  35.  
  36.         // 2. Get the variable that the cursor is on
  37.         VisualCafeCommand.textSelectWord();
  38.         rSelectedWord = sfSource.getSelectionRange();
  39.         sbRange = sfSource.getRangeText(rSelectedWord);
  40.         sVarSelected = sbRange.toString();
  41.  
  42.         // 3. Insert println statement with the selected variable
  43.         VisualCafeCommand.textEndOfLine();
  44.         VisualCafeCommand.textEnter();
  45.         rCurrentPos = sfSource.getSelectionRange();
  46.         if(sVarSelected.equals(""))//No variable selected so just print an empty println();
  47.         {
  48.             sVarLn = "\"\"";
  49.             sbThePrintln = new StringBuffer("System.out.println("+sVarLn+");");
  50.             sfSource.setRangeText(sbThePrintln, rCurrentPos);
  51.             VisualCafeCommand.textEndOfLine();     //Position the cursor in the quotes
  52.             VisualCafeCommand.textCursorLeft();
  53.             VisualCafeCommand.textCursorLeft();
  54.             VisualCafeCommand.textCursorLeft();
  55.         }
  56.         else
  57.         {
  58.             sVarLn = "\""+sVarSelected+": \"+"+sVarSelected;
  59.             sbThePrintln = new StringBuffer("System.out.println("+sVarLn+");");
  60.             sfSource.setRangeText(sbThePrintln, rCurrentPos);
  61.             VisualCafeCommand.textEndOfLine();  //Position cursor at the end of line
  62.  
  63.         }
  64.     }
  65. }